﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;

/// <summary>
/// clip 相关的数据
/// </summary>
[Serializable]
public class MoveClip : PlayableAsset
{
    public MoveClipBehaviour templateBehavior = new MoveClipBehaviour();
    
    public ExposedReference<Transform> startLocation; //引用场景中的对象，需要使用ExposedReference类型
#if UNITY_EDITOR
    [Tooltip("勾选设置自定义End位置")]
#endif
    public bool customEndLocation = false;
 
    public ExposedReference<Transform> endLocation;
 
    
    public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
    {
        Debug.Log("CreatePlayable 创建clip 的 behavior");
        ScriptPlayable<MoveClipBehaviour> playable = ScriptPlayable<MoveClipBehaviour>.Create(graph, templateBehavior);
        MoveClipBehaviour behavior = playable.GetBehaviour(); //将clip的数据转移到behavior中
        behavior.startLocation = startLocation.Resolve(graph.GetResolver()); //ExposedReference 类型的数据需要通关Resolve方法进行转换成关联对象
        behavior.endLocation = endLocation.Resolve(graph.GetResolver());
        behavior.SetEndLocationType(customEndLocation);
        
        return playable;
    }
}
